<style lang="scss">
	page {
		background: #FFFFFF;
		overflow-x: hidden;

		.all {
			width: 750upx;

			.logo {
				width: 344upx;
				height: 344upx;
				margin-top: 26upx;
				margin-left: 203upx;
			}

			.anniu {
				width: 670upx;
				height: 96upx;
				background: #A02731;
				border-radius: 48upx;
				margin-top: 58upx;
				margin-left: 40upx;
				text-align: center;
				line-height: 96upx;
				font-size: 34upx;
				color: #FFFFFF;
			}

			.anniu_new {
				width: 670upx;
				height: 96upx;
				background: #C7CFCB;
				border-radius: 48upx;
				margin-top: 58upx;
				margin-left: 40upx;
				text-align: center;
				line-height: 96upx;
				font-size: 34upx;
				color: #FFFFFF;
			}

			.agreement {
				display: flex;
				margin-top: 40upx;
				margin-left: 60upx;

				.agreement_image {
					width: 30upx;
					height: 30upx;
					margin-top: 3upx;
				}

				.agreement_text {
					margin-left: 30upx;
					height: 36upx;
					font-size: 26upx;
					font-weight: 400;
					color: #999999;
					line-height: 36upx;
				}
			}

			.all_bj {
				width: 520upx;
				height: 388upx;
				position: fixed;
				bottom: 0;
				margin-left: 115upx;
			}

			.new {
				width: 700upx;
				padding: 0;
				margin-left: 25upx;
			}

			.new_box {
				width: 700upx;
				padding: 14upx 0;
				border-bottom: 1upx solid #DDDDDD;
				display: flex;
			}

			.new_box_image {
				width: 52upx;
				height: 54upx;
			}

			.new_box_input {
				margin-left: 8upx;
				margin-top: 8upx;
				width: 478upx;
				height: 40upx;
				font-size: 28upx;
				font-weight: 400;
				color: #222222;
				line-height: 40upx;
			}

			.new_box_text {
				width: 140upx;
				height: 40upx;
				font-size: 28upx;
				font-weight: 400;
				color: #6B542A;
				line-height: 40upx;
			}

			.zhuche {
				text-align: center;
				font-size: 28upx;
				color: #007AFF;
				padding: 20upx 0;
				width: 100%;
			}
		}
	}
</style>
<template>
	<view class="all">
		<image class="logo" src="../../../static/logo.png"></image>
		<!-- <view class="new">
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入账号" @input="phone_input" class="new_box_input" />
			</view>
			<view class="new_box" style="margin-top: 20upx;">
				<input placeholder="请输入密码" @input="password_input" class="new_box_input" />
			</view>
		</view> -->
		<button v-if="is_dianji == 1" class="anniu" @getphonenumber="getUserInfo" open-type="getPhoneNumber">登陆</button>
		<button class="anniu" v-if="is_dianji != 1" @click="panduan">登陆</button>
		<!-- <view class="zhuche" @click="Forgot_tap">忘了密码？</view> -->
		<view class="agreement">
			<image class="agreement_image" @click="dianji"
				:src="is_dianji==0?'../../../static/48.png':'../../../static/67.png'"></image>
			<view class="agreement_text" @click="dianji"> 我已同意 <text style="color: #393E42;"
					@click.stop="Service_tap">《用户协议》</text> 和 <text style="color: #393E42;"
					@click.stop="Privacy_tap">《隐私协议》</text> </view>
		</view>
	</view>
</template>
<script>
	import url_config from '../../../common/config.js'
    const app = getApp()
	export default {
		data() {
			return {
				is_dianji: 0,
				token: '',
				phone: '',
				code: '',
				showText_now: true,
				is_key: '',
				second_now: 60,
				password_data: '',
				password: '',
				invite: '',
				token:'',
				codes:'',
				codess:''
			}
		},
		onLoad() {

		},
		onShow() {
			// this.login_tap()
			// this.user_login_code_api()
		},
		methods: {
			login_tap() {
				var that = this
				that.login_api()
				// uni.login({
				// 	provider: 'weixin',
				// 	success: (loginRes) => {
				// 		that.codess = loginRes.code
				// 		that.login_api()
				// 		// that.loginTest(that.code)
				// 	}
				// })
			},
			token_input(num) {
				this.token = num.detail.value
			},
			Forgot_tap() {
				uni.navigateTo({
					url: '../Forgot_tap/Forgot_tap'
				})
			},
			disembark() {
				uni.navigateTo({
					url:'../login/login'
				})
			},
			dianji() {
				if (this.is_dianji == 0) {
					this.is_dianji = 1
				} else {
					this.is_dianji = 0
				}
			},
			//获取验证码
			code_tap() {
				var reg = /^((13\d)|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[0,1,2,3,5,6,7,8,9,])|(18[0-9])|(19[8,9]))\d{8}/;
				if (reg.test(this.phone)) {
					this.showText_now = false
					this.acquire_api(this.phone) //获取验证码
					var interval = setInterval(() => {
						let times = --this.second_now
						this.second_now = times < 10 ? '0' + times : times //小于10秒补 0
					}, 1000)
					setTimeout(() => {
						clearInterval(interval)
						this.second_now = 60
						this.showText_now = true
					}, 60000)
				} else {
					uni.showToast({
						title: '请输入正确手机号',
						duration: 2000,
						icon: 'none'
					});
				}
			},
			acquire_api(phone) {
				var that = this
				uni.request({
					url: url_config.Url + 'login/sms', //仅为示例，并非真实接口地址。
					data: {
						phone: phone,
					},
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {}
				});
				// that.$request(that.$Api.sms, {
				// 	phone:phone,
				// },"POST").then(res => {
				// })
			},
			phone_input(num) {
				this.phone = num.detail.value
			},
			code_input(num) {
				this.code = num.detail.value
				console.log('this.code', this.code)
			},
			password_input(num) {
				this.password = num.detail.value
			},
			Service_tap() {
				uni.navigateTo({
					url: '/pages/about/about'
				})
			},
			Privacy_tap() {
				uni.navigateTo({
					url: '/pages/guide/guide'
				})
			},
			panduan() {
				var that = this
				if (that.is_dianji != 1) {
					uni.showToast({
						title: '请勾选协议',
						duration: 2000,
						icon: 'none'
					});
					return
				}
			},
			getUserInfo(e) {
				var that = this
				console.log('111')
				// if (that.is_dianji != 1) {
				// 	uni.showToast({
				// 		title: '请勾选协议',
				// 		duration: 2000,
				// 		icon: 'none'
				// 	});
				// 	return
				// }
				var data = {
					access_token: uni.getStorageSync('access_token'),
					code:'',
					encryptedData:e.detail.encryptedData,
					iv:e.detail.iv,
				}
				console.log('e.detail',e)
				if(e.detail.iv!=undefined) {
					that.user_phone_api(data)
				}
			},
			user_phone_api(data) {
				var that = this
				uni.login({
				  provider: 'weixin', //使用微信登录
				  success: function (loginRes) {
					  console.log('loginRes',loginRes)
					var datas = {
						access_token: uni.getStorageSync('access_token'),
						code:loginRes.code,
						encryptedData:data.encryptedData,
						iv:data.iv,
					}
					that.$request(that.$Api.user_phone_api,datas,"POST").then(res => {
						console.log('res',res)
						if (res.data.code == 0) {
							uni.setStorageSync('mobile', res.data.data.mobile);
							that.mobile = res.data.data.mobile
							uni.reLaunch({
								url:'/pages/index/index'
							})
						} else {
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					})
				  }
				});
			},
			user_login_code_api() {
				var that = this
				uni.login({
				  provider: 'weixin', //使用微信登录
				  success: function (loginRes) {
					var datas = {
						code:loginRes.code,
					}
					that.$request(that.$Api.user_login_code_api,datas,"POST").then(res => {
						console.log('res',res)
						if (res.data.code == 0) {
							uni.setStorageSync('access_token', res.data.data.access_token);
							uni.navigateBack()
						} else {
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					})
				  }
				});
			},
			login_api(phone) {
				var that = this
				uni.request({
					url: url_config.Url + 'login/login', //仅为示例，并非真实接口地址。
					data: {
						account: that.phone,
						// code: that.codess,
						// token: that.token,
						password:that.password,
						// codes:that.codes
					},
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						if (res.data.code == 0) {
							uni.setStorageSync('access_token', res.data.data.access_token);
							uni.reLaunch({
								url: '../../index/index'
							}) 
							// 登录注册后 拉起im
                            // app.loginTim()

						} else {
							
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					}
				});
				// that.$request(that.$Api.login, {
				// 	phone:that.phone,
				// 	code:that.code,
				// 	invite:that.invite
				// },"POST").then(res => {
				// 	if( res.data.code == 0 ){
				// 		uni.setStorageSync('access_token', res.data.data.token);
				// 		uni.reLaunch({
				// 			url:'../../index/index/index'
				// 		})
				// 	}else{
				// 		uni.showToast({
				// 			title: res.data.msg,
				// 			duration: 2000,
				// 			icon: 'none'
				// 		});
				// 	}
				// })
			},
		}
	}
</script>
